package com.platform.enums;

import com.google.common.base.Strings;
import com.platform.comm.constants.EnumOption;
import com.platform.comm.enums.IDictEntry;
import com.platform.comm.enums.IEnumItem;
import com.platform.comm.enums.IEnumOption;

import java.util.Arrays;
import java.util.Map;
import java.util.stream.Collectors;
import java.util.stream.Stream;

/**
 * 台账核查结果
 * @author zhangqian
 */
@EnumOption(name = "isSubType")
public enum IsSubType implements IDictEntry, IEnumItem, IEnumOption<String> {

    /**
     * 台账核查结果
     */
    SUCCESS("1", "已上报"),
    FAIL("2", "未上报"),
    NOCHECK("3", "不核查");

    IsSubType(String name, String desc) {
        this.name = name;
        this.desc = desc;
    }

    public final String name;
    public final String desc;

    public String getName() {
        return name;
    }

    public String getDesc() {
        return desc;
    }

    @Override
    public String getKey() {
        return name;
    }

    @Override
    public String getValue() {
        return desc;
    }

    @Override
    public Object getData() {
        return this;
    }

    @Override
    public boolean is(String code) {
        return false;
    }

    @Override
    public String key() {
        return name;
    }

    @Override
    public String value() {
        return desc;
    }

    @Override
    public Map<String, String> enums() {
        return Arrays.stream(values()).collect(Collectors.toMap(IEnumOption::key, IEnumOption::value));
    }
    public static String getDescByName(String name) {
        if (Strings.isNullOrEmpty(name)) {
            return null;
        }
        return Stream.of(values())
                .filter(subType -> subType.getName().equals(name))
                .findFirst()
                .map(IsSubType::getValue)
                .orElse(null);
    }
}
